package ${packagePath};

import pers.cz.enums.ErrorCode;
import pers.cz.exception.BusinessException;
import pers.cz.model.${capsTableName};
import pers.cz.pub.RespBean;
import pers.cz.service.${capsTableName}Service;
<#if swagger=true>
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
</#if>
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @program: PostGirl-panent
 * @description: ${capsTableName}Controller
 * @author: Cheng Zhi
 * @create: ${currentDate}
 **/

<#if swagger=true>
@Api(tags = "${tableDesCriBe}接口")
</#if>
@RestController
@RequestMapping(path = "/api/${capsTableName}")
public class ${capsTableName}Controller {

    @Autowired
    ${capsTableName}Service service;

    <#if swagger=true>
    @ApiOperation(value = "添加${tableDesCriBe}")
    </#if>
    @PostMapping(path = "/add${capsTableName}")
    public RespBean add${capsTableName}(@RequestBody ${capsTableName} ${lowerTableName}, HttpServletRequest request)  {

        int count = service.add${capsTableName}(${lowerTableName});

        return RespBean.ok("成功添加[" + count + "]条");
    }

    /***
     * 多条件查询
     * @param ${lowerTableName}
     * @return
     */
    <#if swagger==true>
    @ApiOperation(value = "${capsTableName}条件查询",notes = "条件查询${capsTableName}方法详情",tags = {"${capsTableName}Controller"})
    </#if>
    @PostMapping(value = "/findList" )
    public List<${capsTableName}> findList(@RequestBody ${capsTableName} ${lowerTableName}){
        //调用${capsTableName}Service实现条件查询${capsTableName}
        List<${capsTableName}> list = service.findList(${lowerTableName});
        return list;
     }

    /***
     * 根据ID删除
     * @param id
     * @return
     */
    <#if swagger==true>
    @ApiOperation(value = "${capsTableName}根据ID删除",notes = "根据主键删除${capsTableName}方法详情",tags = {"${capsTableName}Controller"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "${keyType}")
    </#if>
    @DeleteMapping(value = "/{id}" )
    public RespBean delete(@PathVariable ${keyType} id){
        //调用${capsTableName}Service实现根据主键删除
        int count = service.delete(id);
        return RespBean.ok("成功删除[" + count + "]条");
    }

    /***
     * 修改${capsTableName}数据
     * @param ${lowerTableName}
     * @param id
     * @return
     */
    <#if swagger==true>
    @ApiOperation(value = "${capsTableName}根据ID修改",notes = "根据ID修改${capsTableName}方法详情",tags = {"${capsTableName}Controller"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "${keyType}")
    </#if>
    @PutMapping(value="/{id}")
    public RespBean update(@RequestBody ${capsTableName} ${lowerTableName},@PathVariable ${keyType} id){
        //设置主键值
        ${lowerTableName}.set${keyValue}(id);
        int count = service.update(${lowerTableName});
        return RespBean.ok("成功修改[" + count + "]条");
    }

    /***
     * 根据主键查询${capsTableName}数据
     * @param id
     * @return
     */
    <#if swagger==true>
    @ApiOperation(value = "${capsTableName}根据ID查询",notes = "根据ID查询${capsTableName}方法详情",tags = {"${capsTableName}Controller"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "${keyType}")
    </#if>
    @GetMapping("/{id}")
    public ${capsTableName} findById(@PathVariable ${keyType} id){
        //调用${capsTableName}Service实现根据主键查询${capsTableName}
        ${capsTableName} ${lowerTableName} = service.findById(id);
        return ${lowerTableName};
    }

    /***
     * 查询${capsTableName}全部数据
     * @return
     */
    <#if swagger==true>
    @ApiOperation(value = "查询所有${capsTableName}",notes = "查询所${capsTableName}有方法详情",tags = {"${capsTableName}Controller"})
    </#if>
    @GetMapping
    public List<${capsTableName}> findAll(){
        List<${capsTableName}> list = service.findAll();
        return list;
    }

}
